/* Copyright 2009
 *
 * This program and the accompanying materials
 * are made available under the terms of the
 * Eclipse Public License v1.0 which accompanies
 * this distribution, and is available at
 *
 * 		http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in
 * writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
 * OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * Contributors:
 * 	   IBM Corporation - initial API and implementation for JDT/DLTK
 *     Sean W. Quinn - initial adoption for use with PHP from various sources.
 */
package org.eclipse.php.internal.ui.preferences.formatter.tab;

import java.net.URL;

import org.eclipse.dltk.ui.formatter.IFormatterModifyDialog;
import org.eclipse.dltk.ui.util.SWTFactory;
import org.eclipse.php.core.formatter.PHPCodeFormatterConstants;
import org.eclipse.php.internal.ui.preferences.formatter.PHPFormatterControlManager;
import org.eclipse.php.internal.ui.preferences.formatter.PHPFormatterMessages;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;

/**
 * @author Sean W. Quinn (swquinn@gmail.com)
 */
public class PHPCodeFormatterControlStatementsTabPage extends PHPCodeFormatterTabPage {

	/**
	 * @param dialog
	 */
	public PHPCodeFormatterControlStatementsTabPage(final IFormatterModifyDialog dialog) {
		super(dialog);
	}

	/**
	 * @param manager
	 * @param parent
	 */
	@Override
	protected void doCreateOptions(final PHPFormatterControlManager manager, final Composite parent) {
		createGeneralControlStatementsGroup(manager, parent);
		createIfElseControlStatementsGroup(manager, parent);
	}

	/**
	 * @param manager
	 * @param parent
	 */
	private void createGeneralControlStatementsGroup(final PHPFormatterControlManager manager, final Composite parent) {
		final Group group = SWTFactory.createGroup(parent, PHPFormatterMessages.ControlStatementsTabPage_general_group_title,
				COLUMN_SPAN, 1, GridData.FILL_HORIZONTAL);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_ELSE_IN_IF_STATEMENT,
				PHPFormatterMessages.ControlStatementsTabPage_general_group_insert_new_line_before_else_statements, COLUMN_SPAN);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_CATCH_IN_TRY_STATEMENT,
				PHPFormatterMessages.ControlStatementsTabPage_general_group_insert_new_line_before_catch_statements, COLUMN_SPAN);

		// **
		manager.createCheckbox(group, PHPCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_FINALLY_IN_TRY_STATEMENT,
				PHPFormatterMessages.ControlStatementsTabPage_general_group_insert_new_line_before_finally_statements, COLUMN_SPAN);

		// **
		manager.createCheckbox(group, PHPCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_WHILE_IN_DO_STATEMENT,
				PHPFormatterMessages.ControlStatementsTabPage_general_group_insert_new_line_before_while_in_do_statements, COLUMN_SPAN);
	}

	/**
	 * @param manager
	 * @param parent
	 */
	private void createIfElseControlStatementsGroup(final PHPFormatterControlManager manager, final Composite parent) {
		final Group group = SWTFactory.createGroup(parent,
				PHPFormatterMessages.ControlStatementsTabPage_if_else_group_title, COLUMN_SPAN, 1,
				GridData.FILL_HORIZONTAL);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_KEEP_THEN_STATEMENT_ON_SAME_LINE,
				PHPFormatterMessages.ControlStatementsTabPage_if_else_group_keep_then_on_same_line,
				COLUMN_SPAN);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_KEEP_ELSE_STATEMENT_ON_SAME_LINE,
				PHPFormatterMessages.ControlStatementsTabPage_if_else_group_keep_else_on_same_line,
				COLUMN_SPAN);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_COMPACT_ELSE_IF,
				PHPFormatterMessages.ControlStatementsTabPage_if_else_group_keep_else_if_on_one_line,
				COLUMN_SPAN);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_KEEP_GUARDIAN_CLAUSE_ON_ONE_LINE,
				PHPFormatterMessages.ControlStatementsTabPage_if_else_group_keep_guardian_clause_on_one_line,
				COLUMN_SPAN);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected URL getPreviewContent() {
		return getClass().getResource("bracesPreview.php"); //$NON-NLS-1$
	}
}
